package com.aoxin.controller.client;

import com.aoxin.model.dto.SchoolCourseDto;
import com.aoxin.service.inter.client.ClientIndexService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.PageInfo;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/web/client/")
public class ClientIndexController {
    @Autowired
    private ClientIndexService ClientIndexService;

    /**
     * 获取当前登录用户基本信息
     * @param res
     * @return
     */
    @GetMapping("getUserInfo")
    public AjaxRes getUserInfo(AjaxRes res) {
        try {
            LinkedList<Map<String, Object>> userInfo = ClientIndexService.getUserInfo();
            res.setSucceed(userInfo);
        } catch (Exception e) {
            res.setFailMsg(e.getMessage());
        }
        return res;
    }

    /**
     * 查询用户最近一个预约和未预约信息
     *
     * @param res
     * @return
     */
    @PostMapping("getMyOrderCourse")
    public AjaxRes getMyOrderCourse(AjaxRes res, @RequestParam("pageIndex") Integer pageIndex, @RequestParam("pageSize") Integer pageSize) {
        try {
            PageHelper.startPage(pageIndex, pageSize);
            LinkedList<Map<String, Object>> userInfo = ClientIndexService.getMyOrderCourse();
            PageInfo<Map<String, Object>> page = new PageInfo(userInfo);
            res.setSucceed(page);
        } catch (Exception e) {
            res.setFailMsg(e.getMessage());
        }
        return res;
    }

    /**
     * 查询文章
     * @param res
     * @param type
     * @param size
     * @return
     */
    @GetMapping("getArticle")
    public AjaxRes getArticle(AjaxRes res, Integer type, Integer size) {
        try {
            List<Map<String, Object>> list = ClientIndexService.getArticle(type, size);
            res.setSucceed(list);
        } catch (Exception e) {
            res.setFailMsg(e.getMessage());
        }
        return res;
    }
}
